home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / setup / vbnet / 16 windows forms / windowsformsdemo / scrollableform.vb < prev    next >
Encoding:
Text File  |  2002-03-16  |  13.0 KB  |  318 lines

  1. Public Class ScrollableForm
  2.     Inherits System.Windows.Forms.Form
  3.  
  4. #Region " Windows Form Designer generated code "
  5.  
  6.     Public Sub New()
  7.         MyBase.New()
  8.  
  9.         'This call is required by the Windows Form Designer.
  10.         InitializeComponent()
  11.  
  12.         'Add any initialization after the InitializeComponent() call
  13.  
  14.     End Sub
  15.  
  16.     'Form overrides dispose to clean up the component list.
  17.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  18.         If disposing Then
  19.             If Not (components Is Nothing) Then
  20.                 components.Dispose()
  21.             End If
  22.         End If
  23.         MyBase.Dispose(disposing)
  24.     End Sub
  25.     Friend WithEvents chkAutoScroll As System.Windows.Forms.CheckBox
  26.     Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
  27.     Friend WithEvents Label1 As System.Windows.Forms.Label
  28.     Friend WithEvents txtMarginWidth As System.Windows.Forms.TextBox
  29.     Friend WithEvents txtMarginHeight As System.Windows.Forms.TextBox
  30.     Friend WithEvents Label4 As System.Windows.Forms.Label
  31.     Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
  32.     Friend WithEvents txtPositionY As System.Windows.Forms.TextBox
  33.     Friend WithEvents Label2 As System.Windows.Forms.Label
  34.     Friend WithEvents txtPositionX As System.Windows.Forms.TextBox
  35.     Friend WithEvents Label3 As System.Windows.Forms.Label
  36.     Friend WithEvents chkHScroll As System.Windows.Forms.CheckBox
  37.     Friend WithEvents chkVScroll As System.Windows.Forms.CheckBox
  38.     Friend WithEvents Label5 As System.Windows.Forms.Label
  39.     Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
  40.     Friend WithEvents btnScrollControl As System.Windows.Forms.Button
  41.     Friend WithEvents ListBox2 As System.Windows.Forms.ListBox
  42.     Friend WithEvents Label6 As System.Windows.Forms.Label
  43.     Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
  44.  
  45.     'Required by the Windows Form Designer
  46.     Private components As System.ComponentModel.Container
  47.  
  48.     'NOTE: The following procedure is required by the Windows Form Designer
  49.     'It can be modified using the Windows Form Designer.  
  50.     'Do not modify it using the code editor.
  51.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  52.         Me.Label3 = New System.Windows.Forms.Label()
  53.         Me.Label1 = New System.Windows.Forms.Label()
  54.         Me.txtPositionY = New System.Windows.Forms.TextBox()
  55.         Me.txtPositionX = New System.Windows.Forms.TextBox()
  56.         Me.chkAutoScroll = New System.Windows.Forms.CheckBox()
  57.         Me.GroupBox1 = New System.Windows.Forms.GroupBox()
  58.         Me.txtMarginHeight = New System.Windows.Forms.TextBox()
  59.         Me.Label4 = New System.Windows.Forms.Label()
  60.         Me.txtMarginWidth = New System.Windows.Forms.TextBox()
  61.         Me.GroupBox2 = New System.Windows.Forms.GroupBox()
  62.         Me.Label2 = New System.Windows.Forms.Label()
  63.         Me.btnScrollControl = New System.Windows.Forms.Button()
  64.         Me.chkVScroll = New System.Windows.Forms.CheckBox()
  65.         Me.ListBox1 = New System.Windows.Forms.ListBox()
  66.         Me.Label5 = New System.Windows.Forms.Label()
  67.         Me.chkHScroll = New System.Windows.Forms.CheckBox()
  68.         Me.ListBox2 = New System.Windows.Forms.ListBox()
  69.         Me.Label6 = New System.Windows.Forms.Label()
  70.         Me.ComboBox1 = New System.Windows.Forms.ComboBox()
  71.         Me.GroupBox1.SuspendLayout()
  72.         Me.GroupBox2.SuspendLayout()
  73.         Me.SuspendLayout()
  74.         '
  75.         'Label3
  76.         '
  77.         Me.Label3.Location = New System.Drawing.Point(8, 32)
  78.         Me.Label3.Name = "Label3"
  79.         Me.Label3.Size = New System.Drawing.Size(40, 24)
  80.         Me.Label3.TabIndex = 0
  81.         Me.Label3.Text = "X"
  82.         Me.Label3.TextAlign = System.Drawing.ContentAlignment.TopRight
  83.         '
  84.         'Label1
  85.         '
  86.         Me.Label1.Location = New System.Drawing.Point(8, 32)
  87.         Me.Label1.Name = "Label1"
  88.         Me.Label1.Size = New System.Drawing.Size(48, 24)
  89.         Me.Label1.TabIndex = 0
  90.         Me.Label1.Text = "Width"
  91.         Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
  92.         '
  93.         'txtPositionY
  94.         '
  95.         Me.txtPositionY.Location = New System.Drawing.Point(176, 32)
  96.         Me.txtPositionY.Name = "txtPositionY"
  97.         Me.txtPositionY.Size = New System.Drawing.Size(48, 24)
  98.         Me.txtPositionY.TabIndex = 1
  99.         Me.txtPositionY.Text = ""
  100.         '
  101.         'txtPositionX
  102.         '
  103.         Me.txtPositionX.Location = New System.Drawing.Point(56, 32)
  104.         Me.txtPositionX.Name = "txtPositionX"
  105.         Me.txtPositionX.Size = New System.Drawing.Size(48, 24)
  106.         Me.txtPositionX.TabIndex = 1
  107.         Me.txtPositionX.Text = ""
  108.         '
  109.         'chkAutoScroll
  110.         '
  111.         Me.chkAutoScroll.Location = New System.Drawing.Point(24, 24)
  112.         Me.chkAutoScroll.Name = "chkAutoScroll"
  113.         Me.chkAutoScroll.Size = New System.Drawing.Size(152, 16)
  114.         Me.chkAutoScroll.TabIndex = 0
  115.         Me.chkAutoScroll.Text = "AutoScroll"
  116.         '
  117.         'GroupBox1
  118.         '
  119.         Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtMarginHeight, Me.Label4, Me.txtMarginWidth, Me.Label1})
  120.         Me.GroupBox1.Location = New System.Drawing.Point(24, 56)
  121.         Me.GroupBox1.Name = "GroupBox1"
  122.         Me.GroupBox1.Size = New System.Drawing.Size(264, 64)
  123.         Me.GroupBox1.TabIndex = 1
  124.         Me.GroupBox1.TabStop = False
  125.         Me.GroupBox1.Text = "AutoScrollMargins property"
  126.         '
  127.         'txtMarginHeight
  128.         '
  129.         Me.txtMarginHeight.Location = New System.Drawing.Point(176, 32)
  130.         Me.txtMarginHeight.Name = "txtMarginHeight"
  131.         Me.txtMarginHeight.Size = New System.Drawing.Size(48, 24)
  132.         Me.txtMarginHeight.TabIndex = 1
  133.         Me.txtMarginHeight.Text = ""
  134.         '
  135.         'Label4
  136.         '
  137.         Me.Label4.Location = New System.Drawing.Point(120, 32)
  138.         Me.Label4.Name = "Label4"
  139.         Me.Label4.Size = New System.Drawing.Size(56, 24)
  140.         Me.Label4.TabIndex = 0
  141.         Me.Label4.Text = "Height"
  142.         Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight
  143.         '
  144.         'txtMarginWidth
  145.         '
  146.         Me.txtMarginWidth.Location = New System.Drawing.Point(56, 32)
  147.         Me.txtMarginWidth.Name = "txtMarginWidth"
  148.         Me.txtMarginWidth.Size = New System.Drawing.Size(48, 24)
  149.         Me.txtMarginWidth.TabIndex = 1
  150.         Me.txtMarginWidth.Text = ""
  151.         '
  152.         'GroupBox2
  153.         '
  154.         Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtPositionY, Me.Label2, Me.txtPositionX, Me.Label3})
  155.         Me.GroupBox2.Location = New System.Drawing.Point(24, 136)
  156.         Me.GroupBox2.Name = "GroupBox2"
  157.         Me.GroupBox2.Size = New System.Drawing.Size(264, 64)
  158.         Me.GroupBox2.TabIndex = 1
  159.         Me.GroupBox2.TabStop = False
  160.         Me.GroupBox2.Text = "AutoScrollPosition property"
  161.         '
  162.         'Label2
  163.         '
  164.         Me.Label2.Location = New System.Drawing.Point(128, 32)
  165.         Me.Label2.Name = "Label2"
  166.         Me.Label2.Size = New System.Drawing.Size(40, 24)
  167.         Me.Label2.TabIndex = 0
  168.         Me.Label2.Text = "Y"
  169.         Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
  170.         '
  171.         'btnScrollControl
  172.         '
  173.         Me.btnScrollControl.Location = New System.Drawing.Point(24, 264)
  174.         Me.btnScrollControl.Name = "btnScrollControl"
  175.         Me.btnScrollControl.Size = New System.Drawing.Size(256, 40)
  176.         Me.btnScrollControl.TabIndex = 3
  177.         Me.btnScrollControl.Text = "ScrollControlIntoView(ComboBox1)"
  178.         '
  179.         'chkVScroll
  180.         '
  181.         Me.chkVScroll.Location = New System.Drawing.Point(168, 216)
  182.         Me.chkVScroll.Name = "chkVScroll"
  183.         Me.chkVScroll.Size = New System.Drawing.Size(112, 24)
  184.         Me.chkVScroll.TabIndex = 2
  185.         Me.chkVScroll.Text = "VScroll"
  186.         '
  187.         'ListBox1
  188.         '
  189.         Me.ListBox1.ItemHeight = 18
  190.         Me.ListBox1.Location = New System.Drawing.Point(312, 88)
  191.         Me.ListBox1.Name = "ListBox1"
  192.         Me.ListBox1.Size = New System.Drawing.Size(272, 112)
  193.         Me.ListBox1.TabIndex = 5
  194.         '
  195.         'Label5
  196.         '
  197.         Me.Label5.Location = New System.Drawing.Point(312, 64)
  198.         Me.Label5.Name = "Label5"
  199.         Me.Label5.Size = New System.Drawing.Size(176, 24)
  200.         Me.Label5.TabIndex = 4
  201.         Me.Label5.Text = "two listboxes"
  202.         '
  203.         'chkHScroll
  204.         '
  205.         Me.chkHScroll.Location = New System.Drawing.Point(24, 216)
  206.         Me.chkHScroll.Name = "chkHScroll"
  207.         Me.chkHScroll.Size = New System.Drawing.Size(112, 24)
  208.         Me.chkHScroll.TabIndex = 2
  209.         Me.chkHScroll.Text = "HScroll"
  210.         '
  211.         'ListBox2
  212.         '
  213.         Me.ListBox2.ItemHeight = 18
  214.         Me.ListBox2.Location = New System.Drawing.Point(312, 232)
  215.         Me.ListBox2.Name = "ListBox2"
  216.         Me.ListBox2.Size = New System.Drawing.Size(264, 76)
  217.         Me.ListBox2.TabIndex = 5
  218.         '
  219.         'Label6
  220.         '
  221.         Me.Label6.Location = New System.Drawing.Point(312, 328)
  222.         Me.Label6.Name = "Label6"
  223.         Me.Label6.Size = New System.Drawing.Size(128, 24)
  224.         Me.Label6.TabIndex = 4
  225.         Me.Label6.Text = "one combobox"
  226.         '
  227.         'ComboBox1
  228.         '
  229.         Me.ComboBox1.DropDownWidth = 120
  230.         Me.ComboBox1.Location = New System.Drawing.Point(456, 328)
  231.         Me.ComboBox1.Name = "ComboBox1"
  232.         Me.ComboBox1.Size = New System.Drawing.Size(120, 26)
  233.         Me.ComboBox1.TabIndex = 6
  234.         Me.ComboBox1.Text = "ComboBox1"
  235.         '
  236.         'ScrollableForm
  237.         '
  238.         Me.AutoScaleBaseSize = New System.Drawing.Size(7, 17)
  239.         Me.ClientSize = New System.Drawing.Size(616, 389)
  240.         Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ComboBox1, Me.Label6, Me.ListBox2, Me.ListBox1, Me.Label5, Me.btnScrollControl, Me.chkVScroll, Me.chkHScroll, Me.GroupBox2, Me.GroupBox1, Me.chkAutoScroll})
  241.         Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 11!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  242.         Me.Name = "ScrollableForm"
  243.         Me.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show
  244.         Me.Text = "ScrollableForm"
  245.         Me.GroupBox1.ResumeLayout(False)
  246.         Me.GroupBox2.ResumeLayout(False)
  247.         Me.ResumeLayout(False)
  248.  
  249.     End Sub
  250.  
  251. #End Region
  252.  
  253.     Private Sub ScrollableForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  254.         RefreshControlValues()
  255.     End Sub
  256.  
  257.     Dim ignoreChanges As Boolean
  258.  
  259.     ' refresh contents of controls
  260.     Sub RefreshControlValues()
  261.         ' ignore changes for while the form is being loaded or painted
  262.         ignoreChanges = True
  263.  
  264.         chkAutoScroll.Checked = Me.AutoScroll
  265.         txtMarginWidth.Text = Me.AutoScrollMargin.Width.ToString
  266.         txtMarginHeight.Text = Me.AutoScrollMargin.Height.ToString
  267.         txtPositionX.Text = Me.AutoScrollPosition.X.ToString
  268.         txtPositionY.Text = Me.AutoScrollPosition.Y.ToString
  269.         chkHScroll.Checked = Me.HScroll
  270.         chkVScroll.Checked = Me.VScroll
  271.  
  272.         ignoreChanges = False
  273.     End Sub
  274.  
  275.     Private Sub ScrollableForm_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
  276.         RefreshControlValues()
  277.     End Sub
  278.  
  279.     ' bring ComboBox1 into view
  280.  
  281.     Private Sub btnScrollControl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScrollControl.Click
  282.         Me.ScrollControlIntoView(ComboBox1)
  283.     End Sub
  284.  
  285.     Private Sub chkAutoScroll_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkAutoScroll.CheckedChanged
  286.         If Not ignoreChanges Then
  287.             Me.AutoScroll = chkAutoScroll.Checked
  288.         End If
  289.     End Sub
  290.  
  291.     Private Sub txtMargin_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMarginWidth.TextChanged, txtMarginHeight.TextChanged
  292.         If Not ignoreChanges Then
  293.             On Error Resume Next
  294.             Me.AutoScrollMargin = New Size(CInt(txtMarginWidth.Text), CInt(txtMarginHeight.Text))
  295.         End If
  296.     End Sub
  297.  
  298.     Private Sub txtPosition_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPositionX.TextChanged, txtPositionY.TextChanged
  299.         If Not ignoreChanges Then
  300.             On Error Resume Next
  301.             Me.AutoScrollPosition = New Point(CInt(txtPositionX.Text), CInt(txtPositionY.Text))
  302.         End If
  303.     End Sub
  304.  
  305.     Private Sub chkHScroll_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkHScroll.CheckedChanged
  306.         If Not ignoreChanges Then
  307.             Me.HScroll = chkHScroll.Checked
  308.         End If
  309.     End Sub
  310.  
  311.     Private Sub chkVScroll_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkVScroll.CheckedChanged
  312.         If Not ignoreChanges Then
  313.             Me.VScroll = chkVScroll.Checked
  314.         End If
  315.     End Sub
  316.  
  317. End Class
  318.